package com.cq.hd.app.biz;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cq.hd.common.enums.biz.PayAttachEnum;
import com.cq.hd.common.exception.BusinessException;
import com.cq.hd.common.response.Throw;
import com.cq.hd.member.api.HfMerchantCallbackApi;
import com.cq.hd.member.api.TbAgentEnterApplyApi;
import com.cq.hd.member.api.TbMemberCardApi;
import com.cq.hd.member.api.TbMemberFeeConfigApi;
import com.cq.hd.order.api.HfOrderCallbackApi;
import com.cq.hd.order.api.TbOrderApi;
import com.cq.hd.order.api.pft.PftOrderCallBackParam;
import com.cq.hd.order.api.pft.PftOrderTicketParam;
import com.cq.hd.system.api.HfApi;
import com.cq.hd.system.api.dto.HfVerifyDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

@Component
@Slf4j
public class PftCallbackBiz {

    @Autowired
    private TbOrderApi tbOrderApi;

    public boolean orderCallbck(@RequestBody PftOrderCallBackParam param) {
        log.error("票付通核销回调参数：" + JSONObject.toJSONString(param));
        // 目前只考虑单个商品对应一个票付通门票，即全部核销
        if (param.getOrderState() != null && ("1".equals(param.getOrderState().toString()) || "7".equals(param.getOrderState().toString()))) {
            try {
                return tbOrderApi.pftVerify(param).unpack();
            } catch (BusinessException be) {
                log.error("业务异常：" + be.getMessage());
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
            return false;
        }
        return true;
    }

    public boolean orderTicket(@RequestBody PftOrderTicketParam param) {
        log.error("票付通出票回调参数：" + JSONObject.toJSONString(param));   try {
            return tbOrderApi.pftTicket(param).unpack();
        } catch (BusinessException be) {
            log.error("业务异常：" + be.getMessage());
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return false;
    }
}
